﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Styx.WoWInternals.WoWObjects;

namespace Druidhealz
{
    public partial class Druidhealz 
    {
        private bool Healing()
        {
            WoWPlayer tar = GetHealTarget();
            if (tar != null)
            {
                if (tar.Distance > 40 || !tar.InLineOfSight)
                {
                    Log("Moving to " + tar);
                    MoveTo(tar);
                    return true;
                }
                else
                {
                    String s = null; // spell to cast, initially null
                    bool needCast = false; // do we need to stand still for this spell?
                    double hp = tar.HealthPercent; // our target's HP

                    // Lifebloom Support - Will always keep 3 stacks of Lifebloom on the tank, will let it bloom if tank gets < 50%, else it will refresh it 
                    if (tar.Guid == tank.Guid && !isAuraActive("Lifebloom", tar) && CC("Lifebloom"))
                    {
                        s = "Lifebloom";
                        Log("Tank doesn't have Lifebloom");
                    }
                    else if (tar.Guid == tank.Guid && isAuraActive("Lifebloom", tar) && tar.ActiveAuras["Lifebloom"].StackCount < 3 && CC("Lifebloom"))
                    {
                        s = "Lifebloom";
                        Log("Tank has less than 3 stacks of Lifebloom");
                    }
                    else if (tar.Guid == tank.Guid && isAuraActive("Lifebloom", tar) && tar.ActiveAuras["Lifebloom"].TimeLeft.TotalMilliseconds <= 1700 && hp > hplb && CC("Lifebloom"))
                    {
                        Log("Tank's HP is more than 60% and Lifebloom's duration is " + tar.ActiveAuras["Lifebloom"].TimeLeft.TotalMilliseconds);
                        s = "Lifebloom";
                    }
                    // If Target drops below 40%, use Nature's Swiftness then consume it with Nourish or Healing Touch
                    else if (hp < 40 && CC("Nature's Swiftness"))
                    {
                        s = "Nature's Swiftness";
                    }

                    else if (isAuraActive("Nature's Swiftness", tar) && CC("Healing Touch"))
                    {
                        s = "Healing Touch";
                    }

                    else if (!isAuraActive("Nature's Swiftness", tar) && hp < hpht)
                    {
                        s = "Healing Touch";
                        needCast = true;
                    }
                    // If target drops below `hpsw`, and has rejuvenation, consume it with Swiftmend
                    else if (hp < hpsw && isAuraActive("Rejuvenation", tar) && CC("Rejuvenation"))
                    {
                        s = "Swiftmend";
                    }
                    // If target drops below `hprg` and no other spell is available so far, use Regrowth
                    else if (hp < hprg && !isAuraActive("Regrowth", tar) && CC("Regrowth"))
                    {
                        s = "Regrowth";
                        needCast = true;
                    }
                    // If I'm level 80, keep Rejuvenation up on everyone, at all times, else use it only when they drop below `hprj`, to preserve mana
                    else if ((!isAuraActive("Rejuvenation", tar) && Me.Level >= 80) || (!isAuraActive("Rejuvenation", tar) && hp < hprj) && CC("Rejuvenation"))
                    {
                        s = "Rejuvenation";
                    }

                    if (s != null && CC(s, tar))
                    {
                        if (!C(s, tar))
                        {
                            Log("castfail move to " + tar);
                        }
                        if (!needCast)
                        {
                            MoveTo(tar);
                        }
                        return true;
                    }
                    else
                    {
                        MoveTo(tar);
                        return false;
                    }
                }
            }
            else
            {
                return false;
            }
        }

    }
}
